/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package creditscorejavaapplicationgui;

import com.src.uniandes.ecos.tsp.creditscore.entites.enums.TipoDocEnum;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 *
 * @author AndhyMao
 */
public class CreditScorePanel extends JPanel implements ActionListener {

    private JLabel documentTypeLabel;
    private JComboBox documentTypeComboBox;
    private HashMap<String, Integer> documentTypeMap;
    private JLabel documentLabel;
    private JTextField documentTextField;
    private JButton submitButton;
    private JLabel resultLabel;
    private JLabel resultValueLabel;

    public CreditScorePanel(){

        this.setLayout(null);

        documentTypeLabel = new JLabel("Tipo de documento:");
        documentTypeLabel.setBounds(60, 40 , 160, 30);

        documentTypeComboBox = new JComboBox(loadDocumentTypeComboItems());
        documentTypeComboBox.setBounds(200, 40, 180, 30);

        documentLabel = new JLabel("Documento:");
        documentLabel.setBounds(400, 40, 70, 30);

        documentTextField = new JTextField();
        documentTextField.setBounds(490, 40, 180, 30);

        submitButton = new JButton("Calcular");
        submitButton.setBounds(350, 100, 100, 30);
        submitButton.addActionListener(this);

        resultLabel = new JLabel("CreditScore:");
        resultLabel.setBounds(60, 180, 100, 30);

        resultValueLabel = new JLabel();
        resultValueLabel.setBounds(160, 180, 50, 30);


        this.add(documentTypeLabel);
        this.add(documentTypeComboBox);
        this.add(documentLabel);
        this.add(documentTextField);
        this.add(submitButton);
        this.add(resultLabel);
        this.add(resultValueLabel);


        setSize(800, 300);
        setVisible(true);
    }

    public String[] loadDocumentTypeComboItems(){

        TipoDocEnum[] values = TipoDocEnum.values();
        String[] documentTypeValues = new String[values.length];
        
        if(documentTypeMap == null){
            documentTypeMap = new HashMap<String,Integer>();
        }


        for(int i = 0; i < values.length; i++){

            documentTypeMap.put(values[i].getNombre(), values[i].getId());
            documentTypeValues[i] = values[i].getNombre();
        }
       return documentTypeValues;
    }

    @Override
    public void setSize(int width, int height) {
        super.setSize(width, height);
    }

    @Override
    public void setSize(Dimension d) {
        super.setSize(d);
    }

    public void actionPerformed(ActionEvent e) {

        if(e.getSource() == submitButton){
            resultValueLabel.setText("450");
            
        }
    }

}
